/**
 */

package com.bei_en.teacher.third.pay.common;

import org.apache.commons.codec.digest.DigestUtils;
import com.bei_en.common.util.GenerateUtil;

/**
 * 自主验证
 * @author Guocg
 *
 */
public class Key {

    public static String getWeixinKey(String orderNum) {

	String str = null;
	str = "b"+DigestUtils.md5Hex(orderNum);
	return str;
    }

    public static void main(String[] args) {

	String code = GenerateUtil.geneCode();
	String key = getWeixinKey(code);
	System.out.println(key);
	System.out.println(isValidKey(key, code));
    }

    public static boolean isValidKey(String key, String orderNum) {

	if (key!=null&&key.length()>0) {
	    String md5Hex = DigestUtils.md5Hex(orderNum);
	    return md5Hex.equals(key.substring(1));
	}
	return false;
    }
}
